define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'litestore_p_user/index' + location.search,
                    add_url: 'litestore_p_user/add',
                    edit_url: 'litestore_p_user/edit',
                    del_url: 'litestore_p_user/del',
                    multi_url: 'litestore_p_user/multi',
                    import_url: 'litestore_p_user/import',
                    table: 'litestore_p_user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showToggle:false,  
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate:false},
                        {field: 'group_id', title: __('名录角色'),searchList: {"1":__('默认组'),"7":__('生产师父')},formatter: Table.api.formatter.status},
                        {field: 'nickname', title: __('Nickname'),operate:'LIKE %...%'},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image,operate:false},
                        {field: 'region_city', title: __('Region_city'),operate:'LIKE %...%'},
                        {field: 'address', title: __('Address'),operate:'LIKE %...%'},
                        {field: 'work', title: __('Work'),operate:'LIKE %...%'},
                        {field: 'experience', title: __('Experience')},
                        {field: 'companyname', title: __('Companyname'),operate:'LIKE %...%'},
                        {field: 'level', title: __('会员级别'),searchList: {"1":__('免费会员'),"2":__('普通认证会员'),"3":__('明星认证会员')},formatter: Table.api.formatter.status},
                        {field: 'certify_status', title: __('Certify_status'), searchList: {"1":__('Certify_status 1'),"2":__('Certify_status 2'),"3":__('Certify_status 3')}, formatter: Table.api.formatter.status},
                        //{field: 'appr_status', title: __('Appr_status'), searchList: {"1":__('Appr_status 1'),"2":__('Appr_status 2'),"3":__('Appr_status 3'),"4":__('Appr_status 4'),"5":__('Appr_status 5'),"6":__('Appr_status 6'),"7":__('Appr_status 7')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});